// The complied handlebars templates
// =================================
'use strict';

define([
  'handlebars',
  'text!template/trading/coupon-select.hbs',
  'text!template/trading/coupon-item.hbs'
], function(Handlebars, 
            couponSelect, couponItem) {
  
  Handlebars.registerHelper('currency', function(value, fractionDigits) {
    fractionDigits = fractionDigits || 0
    return (value / 100).toFixed(fractionDigits)
  })
  
  Handlebars.registerHelper('calculate', function(value, mod, fractionDigits) {
    fractionDigits = fractionDigits || 0
    return (value / mod).toFixed(fractionDigits)
  })

  Handlebars.registerHelper('check', function(oldValue, newValue, trueResult, falseResult) {
    if (oldValue instanceof Array) {

      return oldValue.some(function(item) { return item === newValue }) ? trueResult : (falseResult || '')
    } else {
      return oldValue === newValue ? trueResult : (falseResult || '')
    }
  })
  
  Handlebars.registerHelper('equal', function(value, confirm, options){
    if(value === confirm) {
      return options.fn(this);
    } else {
      return options.inverse(this);
    }
  })
  
  return {
    couponSelectTpl:  Handlebars.compile(couponSelect),
    couponItemTpl:    Handlebars.compile(couponItem)
  }
})